package com.ctbu.yyx.cameracontrol.service;


import com.ctbu.yyx.cameracontrol.domain.Camera;
import com.ctbu.yyx.cameracontrol.domain.User;
import com.ctbu.yyx.cameracontrol.repository.CameraRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CameraService {
    @Autowired
    private CameraRepository cameraRepository;

    public List<Camera> findAll(){
        return cameraRepository.findAll();
    }

    public Camera findById(Integer id){
        return cameraRepository.findById(id).orElse(null);
    }

    public List<Camera> findByIp(String ip){
        return cameraRepository.findByIp(ip);
    }

    public Camera insert(Camera camera){
        cameraRepository.save(camera);
        return camera;
    }


    /**
     * 只分页的查询
     * @param pageable
     * @return
     */
    public Page<Camera> findAll(Pageable pageable){
        return cameraRepository.findAll(pageable);
    }


    /**
     * 分页，带过滤的查询
     * @param camera
     * @param pageable
     * @return
     */
    public Page<Camera> findAll(Example<Camera> camera, Pageable pageable){
        return cameraRepository.findAll(camera,pageable);
    }
}
